package com.hspedu.newData.dmsxl.链表.翻转链表;

import com.hspedu.newData.dmsxl.ds.ListNode;
import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-22 
 * @Version: 1.0
 */

public class LC205翻转链表 {


    public ListNode reverseList(ListNode head) {

        ListNode prev = null;
        ListNode cur = head;

        while(cur != null){
            ListNode temp = cur.next;
            cur.next = prev;
            prev = cur;
            cur = temp;
        }
        return prev;
    }

    @Test
    public void test() {
        // 测试代码
        ListNode l1 = new ListNode(6, null);
        ListNode l2 = new ListNode(5, l1);
        ListNode l3 = new ListNode(4, l2);
        ListNode l4 = new ListNode(6, l3);
        ListNode l5 = new ListNode(2, l4);
        ListNode l6 = new ListNode(1, l5);

        reverseList(l6);

        System.out.println("111");
    }


}
